package com.his.admin.controller;


import com.his.admin.service.HospitalTypeService;
import com.his.dao.domain.dto.ListDto;
import com.his.dao.domain.entity.HospitalType;
import com.his.util.annotation.RequiresLogin;
import com.his.util.annotation.RequiresPermissions;
import com.his.util.result.RestResult;
import com.his.util.result.RestResultBuilder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/hospitalType")
@AllArgsConstructor
@Api(value = "医院类型类型模块")
public class HospitalTypeController {
    private HospitalTypeService hospitalTypeService;

    @RequiresLogin
    @RequiresPermissions
    @RequestMapping("/all")
    @ApiOperation(value = "获取医院类型列表",notes = "获取医院类型列表")
    public RestResult all(@RequestBody ListDto listDTO) {
        return hospitalTypeService.all(listDTO);
    }

    @RequiresLogin
    @RequiresPermissions
    @RequestMapping("/all/id")
    @ApiOperation(value = "获取医院类型id列表",notes = "获取医院类型id列表")
    public RestResult allId(@RequestBody HospitalType hospitalType) {
        return hospitalTypeService.allId(hospitalType);
    }

    @RequiresLogin
    @RequiresPermissions
    @RequestMapping("/add")
    @ApiOperation(value = "增加医院类型",notes = "增加医院类型")
    public RestResult add(@RequestBody HospitalType hospitalType) {
        if (hospitalTypeService.save(hospitalType)) {
            return new RestResultBuilder().success();
        }
        return new RestResultBuilder().fail();
    }


    @RequiresLogin
    @RequiresPermissions
    @RequestMapping("/update")
    @ApiOperation(value = "更新医院类型",notes = "更新医院类型")
    public RestResult update(@RequestBody HospitalType hospitalType) {
        if (hospitalTypeService.updateById(hospitalType)) {
            return new RestResultBuilder().success();
        }
        return new RestResultBuilder().fail();
    }

    @RequiresLogin
    @RequiresPermissions
    @RequestMapping("/delete")
    @ApiOperation(value = "删除医院类型",notes = "删除医院类型")
    public RestResult delete(@RequestBody List<Integer> ids) {
        if (hospitalTypeService.removeByIds(ids)) {
            return new RestResultBuilder().success();
        }
        return new RestResultBuilder().fail();
    }

}